---
--类名: EntityFrontLayer.lua
--创建日期: 2017-4-14
--创建人: 金剑
--功能描述: 战斗单位前景层
--修改内容: 
--修改日期: 
--修改人: 
--修改备注: 
--

local EntityFrontLayer = class("EntityFrontLayer",function()
	return display.newLayer("EntityFrontLayer")
end)

local ZOrderList={
    FloatEffect = 4,
    WarningEffect = 999,
}

function EntityFrontLayer:ctor()

    self.floatEffectLayer = display.newLayer()
    self:addChild(self.floatEffectLayer,ZOrderList.FloatEffect)
    self.effectList = {}

    local function onNodeEvent(event)
        if "enter" == event then
            self:onEnter()
        elseif "exit" == event then
            self:onExit()
        end
    end
    self:registerScriptHandler(onNodeEvent)
end

function EntityFrontLayer:onEnter()

end

function EntityFrontLayer:onExit()
	
end

function EntityFrontLayer:showScreenWarning(isVisible, y, screenScale)
    -- if isVisible and self._screenWarningEffect == nil then
    --     self._screenWarningEffect = display.newArmature({path=Res.ActorTargetedScreenEffect.dir,armatureName=Res.ActorTargetedScreenEffect.name,animationName="",skeletonName=Res.ActorTargetedScreenEffect.name})
    --     self:addChild(self._screenWarningEffect, ZOrderList.WarningEffect)
    --     --    self._screenWarningEffect:setScale(1.4)
    --     self._screenWarningEffect:getAnimation():play()
    --     self._screenWarningEffect:setPosition(display.cx, y + 150) 

    --     local box = self._screenWarningEffect:getBoundingBox()
    --     local scale = (display.width/box.width)*screenScale
    --     self._screenWarningEffect:setScale(scale)
    -- end

    -- if self._screenWarningEffect then
    --     self._screenWarningEffect:setVisible(isVisible)
    -- end
end

function EntityFrontLayer:showPointWarning(isVisible, y, posX, rangeDisplay)
    if self.pointWarningEffect == nil and isVisible then
        self.pointWarningEffect = display.newArmature({path=Res.ActorTargetedEffect.dir,armatureName=Res.ActorTargetedEffect.name,animationName="",skeletonName=Res.ActorTargetedEffect.name, async = false,})
        self:addChild(self.pointWarningEffect,ZOrderList.WarningEffect)
        self.pointWarningEffect:getAnimation():play()
    end
    
    if self.pointWarningEffect then
        self.pointWarningEffect:setVisible(isVisible)
        if isVisible then
            if rangeDisplay ~= nil then
                self.pointWarningEffect:setScaleX(1.0)
                local box = self.pointWarningEffect:getBoundingBox()
                local scale = rangeDisplay/box.width
                self.pointWarningEffect:setScaleX(scale)
            else
                self.pointWarningEffect:setScaleX(1.0)
            end

            self.pointWarningEffect:setPositionX(posX)
            self.pointWarningEffect:setPositionY(y)
        end
    end
end

function EntityFrontLayer:addFloatEffectPlayer(id, floatEffectPlayer, zorder)
    floatEffectPlayer:setTag(id)
    self.effectList[id] = floatEffectPlayer
    self.floatEffectLayer:addChild(floatEffectPlayer)
    floatEffectPlayer:setLocalZOrder(zorder)
end

function EntityFrontLayer:setFloatEffectPlayerLocalZOrder(id, zorder)
    local effecPlayer = self.effectList[id]
    if effecPlayer then
        effecPlayer:setLocalZOrder(zorder)
    end
end

function EntityFrontLayer:removeFloatEffectPlayer(id)
    local effecPlayer = self.effectList[id]
    if effecPlayer then
        effecPlayer:removeFromParent()
    end
    self.effectList[id] = nil
end

return EntityFrontLayer
